<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>迭代对象限制</title>
  </head>
  <body>
    <script>
      const obj = {
        name: "张三",
        age: 18,
        gender: "男",
      };

      Reflect.defineProperty(obj, "name", {
        enumerable: false, // 设置为不可枚举
      });

      // 1. for...in
      for (const key in obj) {
        console.log(key, obj[key]);
      }

      // 2. Object.keys()
      const keys = Object.keys(obj);
      for (const key of keys) {
        console.log(keys, obj[key]);
      }
    </script>
  </body>
</html>
